package com.vicykie.admin.web;

import com.vicykie.admin.dao.UserInfoDAO;
import com.vicykie.admin.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/user")
@Controller
@PreAuthorize("hasRole('role_user')")
public class UserController {
    @Autowired
    private UserInfoDAO userInfoDAO;

    @GetMapping("/list")
    @ResponseBody
    public Page getList() {
        return userInfoDAO.findAll(null, Pageable.unpaged());
    }

    @PostMapping("/add")
    @ResponseBody
    public UserInfo addUser(@RequestBody UserInfo userInfo) {
        return userInfoDAO.save(userInfo);
    }
}
